package com.funtester.seven.day6;

import java.sql.*;

public class MysqlT {

    static class Fun {

        public Fun(String name, int age) {
            this.name = name;
            this.age = age;
        }

        String name;
        int age;


    }
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        String url = "jdbc:mysql://49.232.146.223:3306/fun?useUnicode=true&characterEncoding=utf-8&useOldAliasMetadataBehavior=true&useSSL=false";
        String user = "root";
        String passowrd = "";
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection(url, user, passowrd);
        Statement statement = connection.createStatement();
        //以上就是数据库连接过程


        ResultSet resultSet = statement.executeQuery("SELECT * FROM funtester WHERE id = 8;");


        while (resultSet.next()) {
            String name = resultSet.getString("name");
            Integer age = resultSet.getInt("age");
            Fun fun = new Fun(name, age);
            Object[] objects = {name, age};
            System.out.println(resultSet.getRow());
            break;
//            System.out.println("name:"+name+";age:"+age);
//            break;
        }

        resultSet.close();//解析完返回数据时关闭

        int i = statement.executeUpdate("INSERT INTO funtester (name,age) VALUES (\"funtester32\",22);");
        System.out.println(i);

        int i1 = statement.executeUpdate("DELETE FROM funtester WHERE id = 2;");
        System.out.println(i1);

        int i2 = statement.executeUpdate("UPDATE funtester SET age = 100 WHERE id < 8;");
        System.out.println(i2);


        statement.close();
        connection.close();

    }

}
